import UnAccessible from '@/pages/403';
import React from 'react';
import { Dropdown, Popconfirm } from 'antd';
import { GIcon } from 'geminis-react';
import { request } from '@umijs/max';

export const defaultLayout = {
  title: 'Geminis',
  logo: '/image/logo.png',
  layout: 'mix',
  splitMenus: true,
  iconfontUrl: '//at.alicdn.com/t/c/font_2379370_2wvgw9oedx2.js',
  token: {
    header: {
      colorBgHeader: '#292f33',
      colorHeaderTitle: '#fff',
      colorTextMenu: '#dfdfdf',
      colorTextMenuSecondary: '#dfdfdf',
      colorTextMenuSelected: '#fff',
      colorBgMenuItemSelected: '#22272b',
      colorTextMenuActive: 'rgba(255,255,255,0.85)',
      colorTextRightActionsItem: '#dfdfdf',
    },
    sider: {
      colorMenuBackground: '#292f33',
      colorTextMenuTitle: 'rgba(255,255,255,0.95)',
      colorMenuItemDivider: 'rgba(255,255,255,0.15)',
      colorTextMenu: 'rgba(255,255,255,0.75)',
      colorTextMenuSecondary: 'rgba(255,255,255,0.65)',
      colorTextMenuSelected: '#fff',
      colorTextMenuActive: 'rgba(255,255,255,0.95)',
      colorBgCollapsedButton: '#fff',
      colorTextCollapsedButtonHover: 'rgba(0,0,0,0.65)',
      colorTextCollapsedButton: 'rgba(0,0,0,0.45)',
      colorBgMenuItemCollapsedElevated: 'rgba(0,0,0,0.85)',
      colorBgMenuItemHover: 'rgba(0,0,0,0.45)',
      colorBgMenuItemSelected: 'rgba(0,0,0,0.45)',
      colorTextMenuItemHover: 'rgba(255,255,255,0.75)',
      colorTextSubMenuSelected: '#fff',
    },
    pageContainer: {
      colorBgPageContainer: '#fff',
    },
  },
  unAccessible: <UnAccessible />,
};

export const avatarRender = (props: any, dom: any) => {
  return (
    <Dropdown
      menu={{
        items: [
          {
            key: 'cleanCache',
            icon: <GIcon type="icon-refresh" />,
            label: '清除缓存',
          },
          {
            key: 'logout',
            icon: <GIcon type="icon-logout" />,
            label: (
              <Popconfirm
                title="确认退出"
                description="确认要退出系统吗？"
                onConfirm={() => {
                  request('/logout', { method: 'post' })
                    .then(() => {
                      window.location.href = '/';
                    });
                }}
              >
                退出登录
              </Popconfirm>
            ),
          },
        ],
        onClick: ({ key }) => {
          switch (key) {
            case 'cleanCache':
              localStorage.clear();
              window.location.reload();
              break;
          }
        },
      }}
    >
      {dom}
    </Dropdown>
  );
};